﻿////////////////////////////////////////////////////////////////////
//
//	Map_FVG C# Class Library.
//
//	SelezArea
//	
//
//	autore: Gustavo Mainardi 
//	versione: 1.0
//	data: 01/12/2015
//
//
//	Cronologia delle versioni:
//
//	Versione 1.0 01/12/2015
//		versione originale
//
//////////////////////////////////////////////////////////////////////////
using System;
using System.Windows.Forms;
using System.Data.SQLite;

namespace Map_Fvg
{
    public partial class SelezArea : Form
    {

        public SelezArea()
        {
            InitializeComponent();

        }

        private void SelezArea_Load(object sender, EventArgs e)
        {

            int isel = ViewQ.selected_area;
            int Vertices = ViewQ.vectShapesA[isel].nVertices;

            textBox1.Text = isel.ToString();
            textBox2.Text = Vertices.ToString();
            textBox3.Text = ViewQ.vectShapesA[isel].identif;
            int pntSimb = ViewQ.vectShapesA[isel].pntSimb;

            using (SQLiteConnection conn = SetConnection())
            {
                conn.Open();
                using (SQLiteCommand cmd = new SQLiteCommand(conn))
                {
                    cmd.CommandText = "select * from classi";

                    SQLiteDataReader reader = cmd.ExecuteReader();
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            comboBox1.Items.Add(reader.GetString(1).ToString());
                        }
                    }
                    conn.Close();
                }

            }

            string c1 = ViewQ.vectA[pntSimb].codice.Substring(0, 1);
            int index = int.Parse(c1);
            comboBox1.SelectedIndex = index - 1;
            using (SQLiteConnection conn = SetConnection())
            {
                conn.Open();
                using (SQLiteCommand cmd = new SQLiteCommand(conn))
                {

                    cmd.CommandText = "select * from area"; //, classi where area.codice_area = classi.codice_classe";

                    SQLiteDataReader reader = cmd.ExecuteReader();
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            string ss = reader.GetString(0).ToString();
                            string s0 = ss.Substring(0, 1);
                            string s1 = index.ToString();

                            if (s1.CompareTo(s0) == 0)
                            {
                                comboBox2.Items.Add(ss);
                                comboBox3.Items.Add(reader.GetString(1).ToString());
                            }

                        }
                    }
                }
                conn.Close();
            }
            index = comboBox2.FindString(ViewQ.vectA[pntSimb].codice);
            comboBox2.SelectedIndex = index;
            comboBox3.SelectedIndex = index;
            button2.Enabled = false;
            button3.Enabled = false;
        }

        private SQLiteConnection SetConnection()
        {
            string DataSource = "Data Source=";
            DataSource = string.Concat(DataSource, FormIniz.cartellaSimb, ";");
            SQLiteConnection conn = new SQLiteConnection(DataSource);
            return (conn);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.No;
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button3_Click(object sender, EventArgs e)
        {

        }


        private void comboBox1_Click(object sender, EventArgs e)
        {
        }

        private void comboBox2_Click(object sender, EventArgs e)
        {
       }

        private void comboBox3_Click(object sender, EventArgs e)
        {
        }

        private void comboBox2_SelectedValueChanged(object sender, EventArgs e)
        {
            int index = comboBox2.SelectedIndex;
            if (index > -1) comboBox3.SelectedIndex = index;
        }

        private void comboBox3_SelectedValueChanged(object sender, EventArgs e)
        {
            int index = comboBox3.SelectedIndex;
            if (index > -1) comboBox2.SelectedIndex = index;
        }


    }
}
